package com.fasterxml.jackson.core.io;

import com.fasterxml.jackson.core.util.TextBuffer;
import java.lang.ref.SoftReference;

public final class JsonStringEncoder {
    private static final byte[] HB = CharTypes.copyHexBytes();
    private static final char[] HC = CharTypes.copyHexChars();
    protected static final ThreadLocal<SoftReference<JsonStringEncoder>> _threadEncoder = new ThreadLocal();
    protected final char[] _qbuf = new char[6];
    protected TextBuffer _text;

    public JsonStringEncoder() {
        this._qbuf[0] = '\\';
        this._qbuf[2] = '0';
        this._qbuf[3] = '0';
    }

    public static JsonStringEncoder getInstance() {
        SoftReference<JsonStringEncoder> ref = (SoftReference) _threadEncoder.get();
        JsonStringEncoder enc = ref == null ? null : (JsonStringEncoder) ref.get();
        if (enc != null) {
            return enc;
        }
        enc = new JsonStringEncoder();
        _threadEncoder.set(new SoftReference(enc));
        return enc;
    }

    /* JADX WARNING: inconsistent code. */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public char[] quoteAsString(java.lang.String r20) {
        /*
        r19 = this;
        r0 = r19;
        r0 = r0._text;
        r16 = r0;
        if (r16 != 0) goto L_0x0015;
    L_0x0008:
        r16 = new com.fasterxml.jackson.core.util.TextBuffer;
        r17 = 0;
        r16.<init>(r17);
        r0 = r16;
        r1 = r19;
        r1._text = r0;
    L_0x0015:
        r14 = r16.emptyAndGetCurrentSegment();
        r6 = com.fasterxml.jackson.core.io.CharTypes.get7BitOutputEscapes();
        r5 = r6.length;
        r8 = 0;
        r10 = r20.length();
        r12 = 0;
    L_0x0024:
        if (r8 >= r10) goto L_0x009a;
    L_0x0026:
        r0 = r20;
        r2 = r0.charAt(r8);
        if (r2 >= r5) goto L_0x0085;
    L_0x002e:
        r17 = r6[r2];
        if (r17 == 0) goto L_0x0085;
    L_0x0032:
        r9 = r8 + 1;
        r0 = r20;
        r3 = r0.charAt(r8);
        r4 = r6[r3];
        if (r4 >= 0) goto L_0x00a6;
    L_0x003e:
        r0 = r19;
        r0 = r0._qbuf;
        r17 = r0;
        r0 = r19;
        r1 = r17;
        r11 = r0._appendNumeric(r3, r1);
    L_0x004c:
        r17 = r12 + r11;
        r0 = r14.length;
        r18 = r0;
        r0 = r17;
        r1 = r18;
        if (r0 <= r1) goto L_0x00b5;
    L_0x0057:
        r0 = r14.length;
        r17 = r0;
        r7 = r17 - r12;
        if (r7 <= 0) goto L_0x006d;
    L_0x005e:
        r0 = r19;
        r0 = r0._qbuf;
        r17 = r0;
        r18 = 0;
        r0 = r17;
        r1 = r18;
        java.lang.System.arraycopy(r0, r1, r14, r12, r7);
    L_0x006d:
        r14 = r16.finishCurrentSegment();
        r15 = r11 - r7;
        r0 = r19;
        r0 = r0._qbuf;
        r17 = r0;
        r18 = 0;
        r0 = r17;
        r1 = r18;
        java.lang.System.arraycopy(r0, r7, r14, r1, r15);
        r12 = r15;
    L_0x0083:
        r8 = r9;
        goto L_0x0024;
    L_0x0085:
        r0 = r14.length;
        r17 = r0;
        r0 = r17;
        if (r12 < r0) goto L_0x0091;
    L_0x008c:
        r14 = r16.finishCurrentSegment();
        r12 = 0;
    L_0x0091:
        r13 = r12 + 1;
        r14[r12] = r2;
        r8 = r8 + 1;
        if (r8 < r10) goto L_0x00a4;
    L_0x0099:
        r12 = r13;
    L_0x009a:
        r0 = r16;
        r0.setCurrentLength(r12);
        r17 = r16.contentsAsArray();
        return r17;
    L_0x00a4:
        r12 = r13;
        goto L_0x0026;
    L_0x00a6:
        r0 = r19;
        r0 = r0._qbuf;
        r17 = r0;
        r0 = r19;
        r1 = r17;
        r11 = r0._appendNamed(r4, r1);
        goto L_0x004c;
    L_0x00b5:
        r0 = r19;
        r0 = r0._qbuf;
        r17 = r0;
        r18 = 0;
        r0 = r17;
        r1 = r18;
        java.lang.System.arraycopy(r0, r1, r14, r12, r11);
        r12 = r12 + r11;
        goto L_0x0083;
        */
        throw new UnsupportedOperationException("Method not decompiled: com.fasterxml.jackson.core.io.JsonStringEncoder.quoteAsString(java.lang.String):char[]");
    }

    private int _appendNumeric(int value, char[] qbuf) {
        qbuf[1] = 'u';
        qbuf[4] = HC[value >> 4];
        qbuf[5] = HC[value & 15];
        return 6;
    }

    private int _appendNamed(int esc, char[] qbuf) {
        qbuf[1] = (char) esc;
        return 2;
    }
}
